<template>
	<view class="container" v-if="pageStatus == 0">
		<!-- 合伙人信息 -->
		<view class="partner-info">
			<view class="info-left">
				<view class="avatar">
					<u-avatar :src="avatar" style="width: 100%;height: 100%;"></u-avatar>
				</view>
			</view>
			<view class="info-center">
				<text class="nickname">{{name}}</text>
				<br>
				<text class="city">合伙城市：{{partner.cityName}}</text>
				<br>
				<text class="validity">有效期至：{{partner.endTime}} <text
						class="extra-info">(剩余{{partner.endDay}}天)</text></text>
				<br>
			</view>
			<view class="info-right">
				<button class="renew-btn" @click="confirmShow=true">续签</button>
			</view>
		</view>

		<!-- 平台与个人数据 -->
		<view class="data-card">
			<view class="data-header">
				<text>平台当月总访问</text>
				<text class="date"></text>
			</view>
			<view class="data-content">
				<text class="data-value">{{partner.totalMonth}}</text>
			</view>
		</view>

		<view class="data-card">
			<view class="data-header">
				<text>我的当月总访问</text>
				<text class="date"></text>
			</view>
			<view class="data-content">
				<text class="data-value">{{partner.totalMyMonth}}</text>
			</view>
		</view>

		<!-- 今日数据 -->
		<view class="today-data">
			<view class="today-header">
				<text>今日数据</text>
				<text class="today-date">2024-11-17</text>
			</view>
			<view class="today-stats">
				<view class="stat-item">
					<text>总访问：</text>
					<text class="stat-value">{{partner.totalDay}}</text>
				</view>
				<view class="stat-item">
					<text>团队访问：</text>
					<text class="stat-value">{{partner.teamDay}}</text>
				</view>
				<view class="stat-item">
					<text>街道访问：</text>
					<text class="stat-value">{{partner.streetDay}}</text>
				</view>
			</view>
		</view>

		<!-- 我的团队 -->
		<view class="team-info">
			<view class="team-header">
				<text>我的团队</text>
				<text class="team-total">{{partner.myTeamList?partner.myTeamList.length:0}}人</text>
			</view>
			<view class="team-list">
				<view class="team-item" v-for="(item, index) in partner.myTeamList" :key="index">
					<view class="team-avatar">
						<u-avatar :src="item.avatar"></u-avatar>
					</view>
					<view class="team-details">
						<text class="team-name">{{item.name}}</text>
						<text class="team-date">注册日期：{{ item.createTime }}</text>
					</view>
					<view class="team-status">✔</view>
				</view>
			</view>
		</view>
		<u-modal v-model="confirmShow" content="确认要续签吗？" show-cancel-button @confirm="renewalConfirm"></u-modal>
	</view>
	<!-- 待处理页面-->
	<view v-else-if="pageStatus == 1">
		<!-- 申请页-->
		<view class="wxad">
			<ad unit-id="adunit-32ee9f1ef2bea9fa" @error="offAd" @close="offAd"></ad>
		</view>

		<view class="data-card margin-top">
			<view class="data-content">
				<text class="data-value">您已经申请过城市合伙人，请耐心等待审核结果</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageStatus: 0,
				partner: {},
				avatar: "",
				name: "",
				confirmShow: false
			};
		},
		onShow() {
			this.getPartner()
			this.getUserInfo()
		},
		methods: {
			getUserInfo() {
				this.$api.request({
					url: this.$api.getInfo,
				}).then(res => {
					this.avatar = res.data.avatar;
					this.name = res.data.name;
				})
			},
			//获取用户的绑定信息，如果是合伙人，就去合伙人页面，如果不是，则留在申请页面
			getPartner() {
				let userId = uni.getStorageSync('userId')
				this.$api.request({
					url: '/api/partner/getInfoByUserId/' + userId
				}).then(res => {
					if (res.data) {
						console.log(1111111);
						if (res.data.status == 0) {
							this.pageStatus = 1
							this.$forceUpdate()
							uni.showToast({
								title: '你已经申请过城市合伙人，请耐心等待审核',
								icon: 'none'
							});
						} else if (res.data.status == 2) {
							uni.showToast({
								title: '您的城市合伙人权限已过期，请重新申请',
								icon: 'none'
							});
						} else {
							this.$api.request({
								url: '/api/visionCount/totalList',
							}).then(res => {
								this.partner = res.data;
							})
						}
					} else {
						uni.showToast({
							title: '您还不是城市合伙人，请申请',
							icon: 'none'
						});
						uni.redirectTo({
							url: "/pages/my/partner/apply"
						})
					}
				})
			},
			renewalConfirm() {
				this.$api.request({
					url: '/api/partner/renewal',
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: '续签成功',
							icon: 'none'
						});
						this.getPartner()
					}
				})
			}
		}
	};
</script>

<style scoped>
	.margin-top {
		margin: 50upx 10upx;
	}

	.container {
		background-color: #f5f5f5;
		padding: 20px;
	}

	/* 合伙人信息模块 */
	.partner-info {
		display: flex;
		align-items: center;
		flex-direction: row;
		background-color: #fff;
		border-radius: 10px;
		padding: 10px;
		margin-bottom: 15px;
		box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
	}

	.info-left {
		margin-right: 5px;
	}

	.info-center {
		flex: 1;
	}

	.info-right {}

	.nickname {
		font-size: 16px;
		font-weight: bold;
		color: #333;
	}

	.city,
	.validity {
		font-size: 14px;
		color: #666;
		margin-top: 5px;
	}

	.extra-info {
		color: #007bff;
	}

	.renew-btn {
		background-color: #007bff;
		color: #fff;
		padding: 5px 15px;
		border-radius: 5px;
		font-size: 14px;
		margin-left: 10px;
		cursor: pointer;
		width: 150rpx;
	}

	/* 数据卡片模块 */
	.data-card {
		background-color: #fff;
		border-radius: 10px;
		padding: 15px;
		margin-bottom: 15px;
		box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
	}

	.data-header {
		display: flex;
		justify-content: space-between;
		font-size: 14px;
		color: #666;
	}

	.data-content {
		margin-top: 10px;
		text-align: center;
	}

	.data-value {
		font-size: 24px;
		font-weight: bold;
		color: #333;
		display: flex;
		align-items: left;
	}

	/* 今日数据模块 */
	.today-data {
		background-color: #fff;
		border-radius: 10px;
		padding: 15px;
		margin-bottom: 15px;
		box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
	}

	.today-header {
		display: flex;
		justify-content: space-between;
		font-size: 14px;
		color: #666;
		margin-bottom: 10px;
	}

	.today-stats {
		display: flex;
		justify-content: space-between;
	}

	.stat-item {
		text-align: center;
	}

	.stat-value {
		font-size: 18px;
		font-weight: bold;
		color: #333;
		margin-top: 5px;
	}

	/* 团队信息模块 */
	.team-info {
		background-color: #fff;
		border-radius: 10px;
		padding: 15px;
		box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
	}

	.team-header {
		display: flex;
		justify-content: space-between;
		font-size: 16px;
		font-weight: bold;
		color: #333;
		margin-bottom: 15px;
	}

	.team-list {
		display: flex;
		flex-direction: column;
	}

	.team-item {
		display: flex;
		align-items: center;
		margin-bottom: 15px;
	}

	.team-avatar {
		width: 40px;
		height: 40px;
		border-radius: 50%;
		margin-right: 15px;
	}

	.team-details {
		flex: 1;
	}

	.team-name {
		font-size: 14px;
		color: #333;
	}

	.team-date {
		font-size: 12px;
		color: #666;
		margin-top: 5px;
	}

	.team-status {
		font-size: 16px;
		color: #4CAF50;
	}
</style>